/*
 * Copyright (C) 2015 UFreedom
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.ufreedom.floatingview;

import com.ufreedom.floatingview.effect.ScaleFloatingTransition;
import com.ufreedom.floatingview.transition.FloatingTransition;
import ohos.agp.components.Component;

/**
 * FloatingBuilder
 *
 * @author UFreedom
 * @since 2021-04-23
 */
public class FloatingBuilder {
    private FloatingElement mFloatingElement;

    /**
     * FloatingBuilder
     */
    public FloatingBuilder() {
        mFloatingElement = new FloatingElement();
        mFloatingElement.targetViewLayoutResId = -1;
    }

    /**
     * offsetX
     *
     * @param offsetX
     * @return FloatingBuilder
     */
    public FloatingBuilder offsetX(int offsetX) {
        mFloatingElement.offsetX = offsetX;
        return this;
    }

    /**
     * offsetY
     *
     * @param offsetY
     * @return FloatingBuilder
     */
    public FloatingBuilder offsetY(int offsetY) {
        mFloatingElement.offsetY = offsetY;
        return this;
    }

    /**
     * floatingTransition
     *
     * @param floatingTransition
     * @return FloatingBuilder
     */
    public FloatingBuilder floatingTransition(FloatingTransition floatingTransition) {
        mFloatingElement.floatingTransition = floatingTransition;
        return this;
    }

    /**
     * anchorView
     *
     * @param view
     * @return FloatingBuilder
     */
    public FloatingBuilder anchorView(Component view) {
        mFloatingElement.anchorView = view;
        return this;
    }

    /**
     * targetView
     *
     * @param view
     * @return FloatingBuilder
     */
    public FloatingBuilder targetView(Component view) {
        mFloatingElement.targetView = view;
        return this;
    }

    /**
     * targetView
     *
     * @param layResId
     * @return FloatingBuilder
     */
    public FloatingBuilder targetView(int layResId) {
        mFloatingElement.targetViewLayoutResId = layResId;
        return this;
    }

    /**
     * build
     *
     * @return FloatingElement
     * @throws NullPointerException TargetView should not be null
     */
    public FloatingElement build() {

        if (mFloatingElement.targetView == null && mFloatingElement.targetViewLayoutResId == -1) {
            throw new NullPointerException("TargetView should not be null");
        }

        if (mFloatingElement.anchorView == null) {
            throw new NullPointerException("AnchorView should not be null");
        }

        if (mFloatingElement.floatingTransition == null) {
            mFloatingElement.floatingTransition = new ScaleFloatingTransition();
        }
        return mFloatingElement;
    }

}

